package com.ruoyi.patrol.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.patrol.domain.PtGuard;
import com.ruoyi.patrol.domain.PtLineGuard;
import com.ruoyi.patrol.domain.PtStaff;
import com.ruoyi.patrol.domain.dto.BasicSituationOfTheSystemDto;
import com.ruoyi.patrol.domain.dto.SchoolPoint;
import com.ruoyi.patrol.domain.dto.SchoolQuantity;
import com.ruoyi.patrol.mapper.*;
import com.ruoyi.patrol.service.LargeScreenDataService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @author: elis
 * @date: 2023.12.07
 */
@Service
public class LargeScreenDataServiceImpl implements LargeScreenDataService {
    private final PtSchoolMapper ptSchoolMapper;
    private final PtStaffMapper ptStaffMapper;
    private final PtGuardMapper ptGuardMapper;
    private final PtLineMapper ptLineMapper;
    private final PtLineGuardMapper ptLineGuardMapper;
    private final PtLineRecordGuardMapper ptLineRecordGuardMapper;

    private final PtMonitorMapper ptMonitorMapper;

    public LargeScreenDataServiceImpl(PtSchoolMapper ptSchoolMapper, PtStaffMapper ptStaffMapper,
                                      PtGuardMapper ptGuardMapper, PtLineMapper ptLineMapper,
                                      PtLineGuardMapper ptLineGuardMapper, PtLineRecordGuardMapper ptLineRecordGuardMapper, PtMonitorMapper ptMonitorMapper) {
        this.ptSchoolMapper = ptSchoolMapper;
        this.ptStaffMapper = ptStaffMapper;
        this.ptGuardMapper = ptGuardMapper;
        this.ptLineMapper = ptLineMapper;
        this.ptLineGuardMapper = ptLineGuardMapper;
        this.ptLineRecordGuardMapper = ptLineRecordGuardMapper;
        this.ptMonitorMapper = ptMonitorMapper;
    }

    @Override
    public BasicSituationOfTheSystemDto getTheBasics() {
        List<SchoolQuantity> schoolQuantities = ptSchoolMapper.selectSchoolCountByType();
        Integer admins = ptSchoolMapper.selectAdmin();
        Map<String, Object> GuardCountAll = ptGuardMapper.selectPtGuardCountAll();

        int staffs = ptStaffMapper.selectStaff();
        BasicSituationOfTheSystemDto basicSituationOfTheSystemDto = new BasicSituationOfTheSystemDto();
        basicSituationOfTheSystemDto.setSchoolQuantity(schoolQuantities);
        basicSituationOfTheSystemDto.setNumberOfSecurityPersonnel(Convert.toInt(GuardCountAll.get("number")));
        basicSituationOfTheSystemDto.setLicenseHoldingRate(Convert.toFloat(GuardCountAll.get("percent")));
        basicSituationOfTheSystemDto.setAdministrativeStaff(staffs);
        basicSituationOfTheSystemDto.setHeadOfSecurity(admins);
        basicSituationOfTheSystemDto.setSecurityEquipment(85);
        return basicSituationOfTheSystemDto;
    }

    @Override
    public List<SchoolPoint> getSchoolList() {
        return ptSchoolMapper.selectSchoolList();
    }

    @Override
    public Map<String, Object> getSchoolInfo(Integer id) {
        Integer lineCount = ptLineMapper.selectCountByshcoolId(id);
        Integer recordGuardNumber;
        PtLineGuard ptLineGuard = new PtLineGuard();
        ptLineGuard.setSchoolId(Convert.toLong(id));
        recordGuardNumber = ptLineGuardMapper.selectPtLineGuardListdp(ptLineGuard).size();
        String adminName = ptSchoolMapper.selectAdminName(id);
        int guardSize = ptGuardMapper.selectGuardNameFirst(id);
        int staffSize = ptStaffMapper.selectStaffNameFist(id);
        Map<String, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("personResponsibleForSafety", adminName);
        objectObjectHashMap.put("administrativeStaff", staffSize);
        objectObjectHashMap.put("securityPersonnel", guardSize);
        objectObjectHashMap.put("patrolTheLine", lineCount);
        objectObjectHashMap.put("inspectionRecords", recordGuardNumber);
        return objectObjectHashMap;
    }

    @Override
    public List<Map<String, Object>> getLink() {
        String week = DateUtils.aFewDaysAgo(3);
        List<Map<String, Object>> maps = ptLineGuardMapper.selectLineToWeek(week);
        return maps;
    }

    @Override
    public List<Map<String, Object>> getMonitor() {
        List<Map<String, Object>> query = ptMonitorMapper.query();
        return query;
    }

    @Override
    public List<PtStaff> getStaff(Integer id) {
        PtStaff ptStaff = new PtStaff();
        ptStaff.setSchoolId(Long.valueOf(id));

        return ptStaffMapper.selectPtStaffList(ptStaff);
    }

    @Override
    public List<PtGuard> getGuard(Integer id) {
        PtGuard ptGuard = new PtGuard();
        ptGuard.setSchoolId(Long.valueOf(id));
        List<PtGuard> ptGuards = ptGuardMapper.selectPtGuardList(ptGuard);
        return ptGuards;
    }
}
